// JavaScript Document
var Validator={
	Require:/.+/,Email:/^\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b$/i,Url:/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,Number:/^\d+$/,
	Password:/^\S{6,20}$/,
	UserName:/^[^\\\/\'\"\`\~\^\&\{\}\[\]\<\>\*\%\$\#\@\;\:\,\.\?\+\=\|\!]{5,20}$/,Int:/^[-\+]?\d+$/,Double:/^[-\+]?\d+(\.\d+)?$/,
	NickName:/^[^\\\/\'\"\`\~\^\&\{\}\[\]\<\>\*\%\$\#\@\;\:\,\.\?\+\=\|\!]{1,10}$/,Int:/^[-\+]?\d+$/,Double:/^[-\+]?\d+(\.\d+)?$/,
	English:/^[A-Za-z]+$/,Chinese:/^[\u0391-\uFFE5]+$/,
	Tag:/[\\\/\<\>\`\~\'\"\、\!\@\#\$\%\^\&\*\{\}\?\(\)\（\）\《\》\-\:]/,
	DateTime:/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2})$/,
	testRegExp:function(reg,value){return reg.test(value);},
	validateUrl:function(value){return this.testRegExp(this.Url,value);},
	validateEmail:function(value){return this.testRegExp(this.Email,value);},
	validatePassword:function(value){return this.testRegExp(this.Password,value);},
	validateUserName:function(value){return this.testRegExp(this.UserName,value);},
	validateNickName:function(value){return this.testRegExp(this.NickName,value);},
	validateRequireElement:function(element){var value=$F(element);return validateRequire(value);},
	validateRequire:function(value){return this.testRegExp(this.Require,value.Trim());},
	validateDatetime:function(value){return this.testRegExp(this.DateTime,value.Trim());},
	filterTagToArray:function(str){var ret=[];
		var newStr=str.Trim().replace(/[\s　]+/g," ").split(" ");
		if(newStr.length==0){return ret;}
		for(var i=0,count=newStr.length;i<count;i++){
			if(!this.Tag.test(newStr[i])){
				ret.push(this.getChineseSubString(newStr[i],10));
			}
		}
		if(ret.length==0){return ret;}
		if(ret.length==1){return ret;}
		else{return ret.uniq();}
	},
	isChinese:function(str){
		var lst=/[u00-uFF]/;
		return!lst.test(str);
	},
	getChineseStringLength:function(str){
		var strlength=0;
		for(var i=0,count=str.length;i<count;i++){
			if(this.isChinese(str.charAt(i))){
				strlength=strlength+2;
			}else{
				strlength=strlength+1;
			}
		}
		return strlength;
	},
	getChineseSubString:function(inputString,count,addition){
		addition=(typeof addition=="undefined"||addition==null)?"":addition;
		var limit=count*2;
		if(limit>=this.getChineseStringLength(inputString)){
			return inputString;
		}else{
			limit-=addition.length;
			var sb=new StringBuilder();
			for(var i=0,count=inputString.length;i<count;i++){
				var inputChar=inputString.charAt(i);
				sb.append(inputChar);
				if(this.isChinese(inputChar)){
					limit-=2;
					if(limit<0){
						sb.backspace();
						break;
					}
				}else{
					limit--;
				}
				if(limit==0){break;}
			}
			return sb.toString()+addition;
		}
	}
};